package com.xsj.controller;

import com.xsj.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ws-test/user")
public class WebSocketTestController {

    @Autowired
    private ChatClient chatClient;

    /**
     * 模拟用户登录并建立WebSocket连接
     * @param userId 要模拟的用户ID
     * @return String
     */
    @GetMapping("/connect")
    public String connect(@RequestParam("userId") Long userId) {
        chatClient.connect(userId);
        return "用户 " + userId + " 正在尝试连接...";
    }

    /**
     * 模拟用户向商家发送消息
     * @param merchantId 目标商家ID
     * @param content 消息内容
     * @return String
     */
    @GetMapping("/send")
    public String sendMessage(@RequestParam("merchantId") Long merchantId, @RequestParam("content") String content) {
        chatClient.sendMessageToMerchant(merchantId, content);
        return "正在向商家 " + merchantId + " 发送消息: " + content;
    }
} 